<?php
namespace App\Models\Chain\Invite;


use App\Models\Factory\InviteFactory;
use App\Models\Chain\AbstractHandler;
use App\Models\Factory\UserCreditFactory;
use App\Models\Factory\UserFactory;
use App\Models\Orm\UserCreditTypeUser;
use App\Models\Orm\UserInvite;


class CreateCreditAction extends AbstractHandler
{
    private $params = array();
    protected $error = array('error' => '插入用户规则,更新用户积分表失败', 'code' => 7011);


    public function __construct($params)
    {
        $this->params = $params;
    }



    public function handleRequest()
    {
        if ($this->createCredit($this->params) == true) {
            $this->setSuccessor(new CreateCreditLogAction($this->params));
            return $this->getSuccessor()->handleRequest();
        } else {
            return $this->error;
        }
    }



    //更新用户的积分表
    public  function createCredit($params)
    {
        return  UserCreditFactory::updateCreditInvite($params['user_id'],$params['integral']);

    }




}